
$(document).ready(function(){
	//提交方法
	var spanid = $('.choose');
	var rightanswer=["developing","average","dramatically","results","shared","basis","monitor","including","detection","symptoms"];
	var explain = ["第一题的答案","第二题的答案","第三题的答案","第四题的答案","第五题的答案","第六题的答案","第七题的答案","第八题的答案","第九题的答案","第十题的答案",]
	$('.button').on('click',function(event){
		var totalselect = spanid.length;
		var rightcount=0;
		for (i=1;i<=spanid.length;i++) {
		 var text=$('.article').find('#'+i).text();
			if (text==rightanswer[i-1]) {
				rightcount++;
				$('.spans').find('#span'+i).html(i).css("color","blue");
			} else{
			$('.spans').find('#span'+i).html(i).css("color","red");
			}
		}
		var percent=rightcount/totalselect*100+"%";
		$('.rate').html(percent);
		$('.bs-example-modal-lg').modal();
		$('.table-item').addClass('changetab').text("");
		$('.miss').text("");
	});
		
		$('#link').on('click',function(e){
		e.preventDefault();
        for (j=1;j<=spanid.length;j++) {
        	 var text=$('.article').find('#'+j).text();
        	 if(text!=rightanswer[j-1]) {
        	 	$('.article').find('#'+j).addClass('wronganswer').css("color","red");
        	 	$('#right'+j).addClass('rightchoose').text(rightanswer[j-1]);
        	 	$('#href'+j).css("background","coral");
        	 }else{
        	 	$('#href'+j).css("background","rgb(108,211,189)");
        	 }
        }
        //实现答案解析
       $('.article>.choose').unbind('click');
       $('.article>.choose').bind('click',function(){
       	switch($('.article>.choose').index(this)){
       		case 0:
       		$('.table-item').text(explain[0]); break;
       		case 1:
       		$('.table-item').text(explain[1]); break;
            case 2:
            $('.table-item').text(explain[2]); break;
            case 3:
            $('.table-item').text(explain[3]); break;
            case 4:
            $('.table-item').text(explain[4]); break;
            case 5:
            $('.table-item').text(explain[5]); break;
            case 6:
            $('.table-item').text(explain[6]); break;
            case 7:
            $('.table-item').text(explain[7]); break;
            case 8:
            $('.table-item').text(explain[8]); break;
            case 9:
            $('.table-item').text(explain[9]); break;
       	}
       });
	});
	//导航
	$(".sepe").find('span').hide();
	$(".sepe").find('span').first().show();
	$('ul.sepe>li').on('click',function(e){
		e.preventDefault();
		var currentTB = $('ul.sepe>li');
		$(currentTB).find('span').hide();
		$(this).find('span').show();
		var current = $(this).text();
	    var id = $('#href'+current).find('a').attr("href");
	    trigger(id);

	});
	//table
		$('.article>.choose').on("click",function(e){
		e.preventDefault();
		var current = $('.article>.choose');
		$(current).removeClass('chooseItem');
		$(this).addClass('chooseItem');
		init(this);
	}); 

});
function trigger(event){
    	$(event).trigger("click");
	}
function init(e){
			var $table = $('.table-item');
	$table.on("mouseover",function(ev){
		var ev = ev||window.event;
		 var target = ev.target;
		 if (target.nodeName.toLowerCase()=="li") {
		 	var td = target.innerHTML;
		 	$(e).text(td);
		 	target.style.color="#30b1d5";

		 }
	});
	$table.on("mouseout",function(ev){
		var ev = ev||window.event;
		 var target = ev.target;
		 if (target.nodeName.toLowerCase()=="li"){
		 target.style.color="";
		 }
   });
	$table.on("click",function(ev){
		var ev = ev||window.event;
		 var target = ev.target;
		 if (target.nodeName.toLowerCase()=="li") {
		 	var td = target.innerHTML;
		 	$(e).removeClass('chooseItem').css("color","#337AB7");
		 	$table.unbind('mouseover');
		 }
	});
}
//	function tableover(){
//		var $table = $('table');
//	$table.on("mouseover",function(ev){
//		var ev = ev||window.event;
//		 var target = ev.target;
//		 if (target.nodeName.toLowerCase()=="td") {
//		 	var td = target.innerHTML;
//		 	$('.choose').text(td);
//		 }
//	});
//	}
//	function tableclik(){
//		var $table = $('table');
//	$table.on("click",function(ev){
//		var ev = ev||window.event;
//		 var target = ev.target;
//		 if (target.nodeName.toLowerCase()=="td") {
//		 	var td = target.innerHTML;
//		 	$('.choose').text(td);
//		 	$('.choose').removeClass('chooseItem');
//		 }
//		 });
//	}
